import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login'
import Home from '../components/Home'
import UserList from '../components/user/userList'
import PowList from '../components/power/PowList'
import RoleList from '../components/power/RoleList'

import category from '../views/emsboot/category'
import product from '../views/emsboot/product'
import warehouse from '../views/emsboot/warehouse'
import Welcome from '../components/Welcome'
import order from '../views/emsboot/order/index'
import orderout from '../views/emsboot/order/out'

Vue.use(VueRouter)

const routes = [{ path: '/', redirect: '/login' }, { path: '/login', component: Login }, {
  path: '/home', component: Home, redirect: '/welcome', children: [{
    path: '/welcome', component: Welcome
  }, {
    path: '/userList', component: UserList
  }, {
    path: '/powList', component: PowList
  }, {
    path: '/roleList', component: RoleList
  }, {
    path: '/orderout', component: orderout
  }, {
    path: '/category', component: category
  }, {
    path: '/product', component: product
  }, {
    path: '/balance', component: () => import('../views/emsboot/product/balance.vue')
  },  {
    path: '/warehouse', component: warehouse
  }, {
    path: '/order', component: order
  },
    {
      path: '/auditor/input', component: () => import('../views/emsboot/auditor/input/index.vue')
    },
    {
      path: '/auditor/output', component: () => import('../views/emsboot/auditor/output/index.vue')
    },
    {
      path: '/customer/input', component: () => import('../views/emsboot/customer/input/index.vue')
    },
    {
      path: '/customer/order/input', component: () => import('../views/emsboot/customer/order/index.vue')
    }, {
      path: '/customer/order/output', component: () => import('../views/emsboot/customer/order/out.vue')
    },
    {
      path: '/customer/output', component: () => import('../views/emsboot/customer/output/index.vue')
    },
    {
      path: '/retake', component: () => import('../views/emsboot/retake/index.vue')
    },
    {
      path: '/warehouse/move', component: () => import('../views/emsboot/warehouse/move.vue')
    },
    {
      path: '/order/analysis', component: () => import('../views/emsboot/order/analysis.vue')
    }

  ]
}]

const router = new VueRouter({
  routes
})
//挂载路由导航守卫
router.beforeEach((to, from, next) => {
  //to将要访问的路径
  //from代表从哪个路径跳转过来
  //next是一个函数表示放行
  //next()放行  next('/login') 跳转到登登录页
  if (to.path == '/login') return next()
  //获取用户数据
  const token = window.sessionStorage.getItem('token')

  if (!token) return next('/login')
  next()

})
export default router
